package com.ecommerce.service;

import com.ecommerce.entity.Category;
import com.ecommerce.repository.CategoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {

    @Autowired
    private CategoryRepository categoryRepository;

    /**
     * 获取所有激活的分类
     */
    public List<Category> getActiveCategories() {
        return categoryRepository.findActiveCategoriesOrderBySortOrder();
    }

    /**
     * 获取前N个分类
     */
    public List<Category> getTopCategories() {
        return categoryRepository.findTopCategories();
    }

    /**
     * 根据ID获取分类
     */
    public Category getCategoryById(Long id) {
        return categoryRepository.findById(id).orElse(null);
    }

    /**
     * 根据名称获取分类
     */
    public Category getCategoryByName(String name) {
        return categoryRepository.findByName(name);
    }
} 